function [logL_neg]=likelihood_obj(parameter,ability_metric,LowCost_Ability,HighCost_Ability,V_l,V_h,outcome,tpORtp3h,Cpm25,parameter_fixed)


N=size(LowCost_Ability,1);

% Parameters that are fixed
%cutoff_tp=parameter_fixed(1);
%cutoff_pm=parameter_fixed(2);
%delta_0  =parameter_fixed(3);

% Parameters that are estimated 
k       =parameter(1);
%delta_tp=parameter(3);
%delta_pm=parameter(4);
eta     =parameter(5);           % PSYCHOLOGICAL MOMENTUM (eta is hypothesized to be negative): l won previous set adds eta to c_l this period; l lost previous set adds eta to c_h this period
                
% Delta changes separately in the log of (1 +) the temperature or PM2.5 difference relative to a cutoff, i.e., temperature of 27 -> log (1 + 27 - cutoff) = log (1 + 27 - 27) = log 1 = 0; 28->.7 of delta; 43->2.8   
%delta = repmat(delta_0,N,1) + delta_tp * log( max( (tpORtp3h - repmat(cutoff_tp,N,1)) , 0) + ones(N,1)) + delta_pm * log( max( (Cpm25 - repmat(cutoff_pm,N,1)) , 0) + ones(N,1));


% Marginal cost (mc) function:
% inputs: ability metric, cost parameter, LowCost_Ability, HighCost_Ability
% outputs: c_l, c_h
[c_l,c_h]=mc(ability_metric,parameter,LowCost_Ability,HighCost_Ability);

% transition_prob_oneshot:
% inputs: c_l, c_h, V_l, V_h, k
% outputs: p_l_winoneshot=p_l_win3, p_h_winoneshot=p_h_win3
% PSYCHOLOGICAL MOMENTUM (eta is hypothesized to be negative): l won previous set adds eta to c_l this period; l lost previous set adds eta to c_h this period
[p_lwin3_lwon2,p_llose3_lwon2,p_lwin3_llost2,p_llose3_llost2]=transition_prob_oneshot(c_l,c_h,V_l,V_h,k,eta);

% transition_prob_stage2:
% inputs: c_l, c_h, V_l, V_h, temperature, PM2.5, k, parameters of the delta function, calls on transition_prob_oneshot
% outputs: Continuation values (in stage 3) conditional on stage-2 outcome (and stage-1 history), stage-2 transition probabilities  
[~,~,~,~,~,~,~,~,p_lwin2_lwon1,p_llose2_lwon1,p_lwin2_llost1,p_llose2_llost1]=transition_prob_stage2(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h);

% transition_prob_stage1:
% inputs: c_l, c_h, V_l, V_h, temperature, PM2.5, k, parameters of the delta function, calls on transition_prob_stage2
% outputs: Continuation values (in stage 2) conditional on stage-1 outcome, stage-1 transition probabilities   
[~,~,~,~,p_lwin1,p_llose1]=transition_prob_stage1(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h);



% Compute probabilities for each match outcome (this can be sped up if necessary subsequently; e.g., for simulated likelihood)
prob_ll =p_lwin1 .*  p_lwin2_lwon1;
prob_lhl=p_lwin1 .* p_llose2_lwon1.* p_lwin3_llost2;
prob_lhh=p_lwin1 .* p_llose2_lwon1.*p_llose3_llost2;
prob_hll=p_llose1.* p_lwin2_llost1.* p_lwin3_lwon2;
prob_hlh=p_llose1.* p_lwin2_llost1.*p_llose3_lwon2;
prob_hh =p_llose1.*p_llose2_llost1;
prob=[prob_ll prob_lhl prob_lhh prob_hll prob_hlh prob_hh];
likelihood_contribution=sum(prob.*outcome,2);
    
    
logL_neg=-ones(1,N)*log(likelihood_contribution);
    

end